import type { CardItem } from '/@/api/general/model/cardModel';

export type GameId = {
  game_id: string;
};

// 套牌配置数据结构
export enum SearchLogicTypeEnum {
  OR = 'or',
  AND = 'and',
}

export enum SearchSettingTypeEnum {
  TEXT = 'text',
  IMAGE = 'image',
}

export type DeckConfigConditionItem = {
  attr_key: string; //属性key
  condition: '=' | '<' | '>' | '<=' | '>=';
  value: string; // 值
};

export type DeckConfigGroupItem = {
  group_name: string; //分组名称
  logic: SearchLogicTypeEnum;
  conditions: DeckConfigConditionItem[];
};

export type SearchMapItem = {
  key: string;
  value: string;
};

export type SearchSettingItem = {
  title: string;
  attr_key: string;
  show_type: SearchSettingTypeEnum;
  is_mapping: 0 | 1;
  mapping: SearchMapItem[];
};

export type DeckConfigData = {
  index_title: string; //首页标题
  seo_keyword: string;
  has_price: 0 | 1; //是否存在价格跳转，0-否，1-是
  has_series: 0 | 1; //是否存在系列，0-否，1-是
  is_show_ename: 0 | 1; // 是否展示其他名称
  is_show_card_no: 0 | 1; // 是否展示卡牌编号
  card_group: DeckConfigGroupItem[];
  tags: string[];
  search_setting: SearchSettingItem[];
  show_setting: SearchSettingItem[];
  trade_game_id: string;
};

// 套牌详情数据结构
export enum ReviewStatusEnum {
  ING,
  PASS,
  FAIL,
}

export type DeckInfoCardItem = Writable<
  CardItem & {
    // price?: number; // 单价
    series_abbr?: string; // 系列缩写
    number?: number;
    group_name?: string; //分组名称
    card_no?: string;
  }
>;

export type DeckInfoItem = {
  group_name: string;
  card_number: number;
  card_list: DeckInfoCardItem[];
};

export type DeckDetail = {
  deck_id: number;
  user_id: number;
  deck_name: string;
  deck_desc: string;
  card_number: number;
  price: number;
  deck_info: DeckInfoItem[];
  updated_at: number;
  publish_at: number;
  review_status: ReviewStatusEnum;
  nickname: string;
  is_open: 0 | 1;
  tags: string[]; // 实际返回为字符串
  likes_number: number;
  is_like: 0 | 1 | 2; // 0 无操作 1 赞  2 踩
};

// 套牌列表数据结构
export type DeckItem = Pick<
  DeckDetail,
  'deck_id' | 'deck_name' | 'updated_at' | 'card_number' | 'review_status' | 'price' | 'is_open' | 'tags'
> & {
  isCheck: boolean;
};

export type DeckList = {
  total: number;
  rows: DeckItem[];
};

export type DeckListQuery = Writable<GameId & { page: number; size: number }>;

// 套牌创建和编辑参数
export type CreateDeck = Writable<
  GameId & Pick<DeckDetail, 'deck_id' | 'deck_name' | 'deck_info' | 'deck_desc' | 'is_open' | 'tags'>
>;

// 卡牌详情（添加使用）
export type DeckCardDetail = {
  id: number;
  name: string;
  ename: string;
  rule_name: string;
  game_id: string;
  series_id: number;
  card_no: string;
  sindex: string;
  sindex_order: number;
  description: string;
  price: number;
  img: string;
  is_visible: 0 | 1;
  keyword_ids: string;
  keyword_names: string;
  rarity: string;
  artist: string;
  rule: string;
  attack: number;
  defense: number;
  mana: number;
  is_deck: number;
  attr01: any;
  attr02: any;
  attr03: any;
  attr04: any;
  attr05: any;
  attr06: any;
  attr07: any;
  attr08: any;
  attr09: any;
  attr10: any;
  attr11: any;
  attr12: any;
  attr13: any;
  attr14: any;
  attr15: any;
  attr16: any;
  attr17: any;
  attr18: any;
  attr19: any;
  attr20: any;
  publish_time: number;
  created_at: number;
  created_user: string;
  updated_at: number;
  updated_user: string;
  series_abbr: string;
};
